package game;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MarkerQueue {

    private Lock lock = new ReentrantLock();
    private Condition isEmpty = lock.newCondition();
    private int column;
    
    
    /*
     * Adds a column that has been clicked in the gameboard if its waiting for one
     */
    public void addColumnToQueue(int column) {
        lock.lock();
        try {
            this.column = column;
            isEmpty.signalAll();
        } finally {
            lock.unlock();
        }
    }

    /*
     * Waits for the next move from user then returns it.
     */
    
    public int getNextMoveFromQueue() {
        lock.lock();
        try {
            isEmpty.await();
            return column;
        } catch (InterruptedException ex) {
            System.out.println("InterruptedException");
        } finally {
            lock.unlock();
        }
        return column;

    }
}
